package concurrencyCookBook;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

public class RejectedExecutionHandlerDemo {

	public static void main(String[] args) {
		ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors
				.newCachedThreadPool();
		RejectedExecutionHandlerHDemo handler = new RejectedExecutionHandlerHDemo();
		executor.setRejectedExecutionHandler(handler);
		for(int i=0;i<10;i++){
			executor.execute(new Reject());
		}
		executor.shutdown();
		executor.execute(new Reject());
	}
}

class Reject implements Runnable {

	@Override
	public void run() {
		System.out.println("AAAA");
	}

}

class RejectedExecutionHandlerHDemo implements RejectedExecutionHandler {
	@Override
	public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
		System.out.println("处理被拒接的任务");

	}

}
